home *** CD-ROM | disk | FTP | other *** search
/ PC User 2003 December / Australian PC User - December 2003 (CD2).iso / software / apps / files / dwmx2k4.exe / Disk1 / data1.cab / Configuration_En / Translators / transData.js < prev    next >
Encoding:
JavaScript  |  2003-09-05  |  11.5 KB  |  274 lines

  1. //SHARE-IN-MEMORY=true
  2. // Copyright 2000, 2001, 2002, 2003 Macromedia, Inc. All rights reserved.
  3.  
  4. /////////////////////////////////////////////////// transData Class  //////////////////////////////////////////////////////
  5.  
  6. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  7. // Function : transData_transData
  8. // Purpose    : data store for a participants translation information
  9. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  10. function transData(part, type, openTag, closeTag, attributes, display, insertBefore, insertAfter, beginMegaLock, endMegaLock, lockAttributes)
  11. {
  12.     // Members
  13.     this.participant    = part;            // participant name
  14.     this.type            = type;            // blank|custom|tabbedRegion|dataSource|dynamicData
  15.     this.openTag        = openTag;        // may contain replace tokens
  16.     this.closeTag        = closeTag;        // may contain replace tokens
  17.     this.attributes        = attributes;    // may contain replace tokens
  18.     this.display        = display;        // may contain replace tokens
  19.     this.insertBefore    = insertBefore;    //
  20.     this.insertAfter    = insertAfter;    // 
  21.     this.beginMegaLock    = beginMegaLock;//
  22.     this.endMegaLock    = endMegaLock;  //
  23.     this.lockAttributes = lockAttributes;
  24. }
  25.     // methods
  26.     transData.prototype.replaceTokens    = transData_replaceTokens;
  27.     transData.prototype.replaceToken    = transData_replaceToken;
  28.     transData.lookupTransValue            = transData_lookupTransValue;
  29.     transData.lookupTransArray            = transData_lookupTransArray;
  30.     transData.parse                        = transData_parse;
  31.     transData.copy                        = transData_copy;
  32.  
  33. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  34. // Function : transData_replaceTokens
  35. // Purpose    : replace tokens of the form @@name@@ with tokens[name]
  36. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  37. function transData_replaceTokens(tokens)
  38. {
  39.     this.openTag = this.replaceToken(this.openTag, tokens);
  40.     this.closeTag = this.replaceToken(this.closeTag, tokens);
  41.     this.attributes = this.replaceToken(this.attributes, tokens);
  42.     if (this.attributes && this.attributes.indexOf("@@") != -1)
  43.     {
  44.         this.attributes = this.attributes.replace(/\s*\w+=@@\w+@@/g, "");
  45.     }
  46.     if (this.type == "dynamic data" && this.attributes.indexOf("mmTranslatedValueDynValue") != -1)
  47.     {
  48.         if (dw.getDynamicTextFormat() == "{}")
  49.         {
  50.             this.attributes = this.attributes.replace(/mmTranslatedValueDynValue="VALUE=\{[^\}]+\}"/gi, "mmTranslatedValueDynValue=\"VALUE=\{\}\"");
  51.         }
  52.     }
  53.  
  54.     if (this.display)
  55.     {
  56.         if (this.type == "dynamic data" && dw.getDynamicTextFormat() == "{}")
  57.         {
  58.             this.display = "{}";
  59.         }
  60.         else
  61.         {
  62.             this.display = this.replaceToken(this.display, tokens);
  63.             if (this.display.indexOf("@@") != -1)
  64.             {
  65.                 this.display = this.display.replace(/@@\w+@@/g, "");
  66.             }
  67.             if (this.type == "tabbed region start")
  68.             {
  69.                 this.display = escape(this.display);
  70.             }
  71.         }
  72.     }
  73. }
  74.  
  75. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  76. // Function : transData_replaceToken
  77. // Purpose    : replace specified tokens of the form @@name@@ with tokens[name]
  78. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  79. function transData_replaceToken(value, tokens)
  80. {
  81.     var shortToken;
  82.     if (value && value.indexOf("@@") != -1)
  83.     {
  84.         for (var i in tokens)
  85.         {
  86.             shortToken = tokens[i];
  87.             if (shortToken.length > 19)
  88.                 shortToken = shortToken.substr(0, 16) + "...";
  89.  
  90.             if (value.indexOf("@@"+i+"@@") != -1)
  91.                 value = value.replace(RegExp("@@" + i + "@@","g"), tokens[i]);
  92.             if (value.indexOf("@@limit(" + i + ")@@") != -1)
  93.                 value = value.replace(RegExp("@@limit[(]" + i + "[)]@@", "g"), shortToken);
  94.             if (value.indexOf("@@escape(" + i + ")@@") != -1)
  95.                 value = value.replace(RegExp("@@escape[(]" + i + "[)]@@", "g"), escape(tokens[i]));
  96.             if (value.indexOf("@@limitAndEscape(" + i + ")@@") != -1)
  97.                 value = value.replace(RegExp("@@limitAndEscape[(]" + i + "[)]@@", "g"), escape(shortToken));
  98.         }
  99.  
  100.         var current = 0;
  101.         var subValue = value;
  102.         var temp = subValue.search(/@@MM.LABEL_\w+@@/);
  103.         var replacement;
  104.  
  105.         while (temp > -1)
  106.         {
  107.             var varEnd = value.indexOf("@@", current+temp+2);
  108.             var variable = value.substr(current+temp+2, varEnd-current-temp-2);
  109.             replacement = eval(variable);
  110.             value = value.replace(RegExp("@@" + variable + "@@", "g"), replacement);
  111.             current = current+temp+replacement.length;
  112.             subValue = value.substr(current);
  113.             temp = subValue.search(/@@MM.LABEL_\w+@@/);
  114.         }
  115.     }
  116.  
  117.     return value;
  118. }
  119.  
  120. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  121. // Function : transData_lookupTransValue
  122. // Purpose    : pulls one value out of a XML <translation> tag
  123. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  124. function transData_lookupTransValue(participant, translation, name)
  125. {
  126.     return dw.getExtDataValue(participant, "translator", "translations", translation, name);
  127. }
  128.  
  129. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  130. // Function : transData_lookupTransArray
  131. // Purpose    : pulls one array out of a XML <translation> tag
  132. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  133. function transData_lookupTransArray(participant, translation, name)
  134. {
  135.     return dw.getExtDataArray(participant, "translator", "translations", translation, name);
  136. }
  137.  
  138. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  139. // Function : transData_parse
  140. // Purpose    : pulls values out of XML <translation> tag and creates a new transData
  141. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  142. function transData_parse(participant, translation, translatorInfoItem, manager)
  143. {
  144.   var whereToSearch = transData.lookupTransValue(participant, translation, "whereToSearch").toLowerCase();
  145.  
  146.   // ===========================================================================
  147.   // Put this participant into the appropriate partition.
  148.   // ===========================================================================
  149.  
  150.   if (whereToSearch.indexOf("tag+") == 0)
  151.   {
  152.     var limitSearch =
  153.       transData.lookupTransValue(participant, translation, "limitSearch").toLowerCase();
  154.     
  155.     // Look for "tagonly" or "all" tag patterns that aren't
  156.     // covered by the server model "alwaysCheckTag" rules
  157.     var tagName = whereToSearch.substr(4);
  158.     if (!translatorInfoItem.lookInAllTags &&
  159.         limitSearch.indexOf("attribute+") != 0 &&
  160.         !manager.alwaysCheckTag(tagName))
  161.       translatorInfoItem.lookInAllTags = true;
  162.     
  163.     whereToSearch = whereToSearch + ":" + limitSearch;
  164.     
  165.     if (limitSearch.indexOf("attribute+") == 0)
  166.     {
  167.       translatorInfoItem.attributeParticipants[participant] = true;
  168.     }
  169.     else if (limitSearch.indexOf("tagonly") == 0)
  170.     {
  171.       translatorInfoItem.tagOnlyParticipants[participant] = true;
  172.     }
  173.     else
  174.     {
  175.       translatorInfoItem.outerHTMLParticipants[participant] = true;
  176.     }
  177.   }
  178.   else if (whereToSearch == "directive")
  179.     translatorInfoItem.directiveParticipants[participant] = true;
  180.   else if (whereToSearch == "text")
  181.     translatorInfoItem.textParticipants[participant] = true;
  182.     
  183.   // ===========================================================================
  184.   // Retrieve all of the transDataValues
  185.   // ===========================================================================
  186.  
  187.   if (translatorInfoItem[participant].translations[whereToSearch] == null)
  188.   {
  189.     translatorInfoItem[participant].translations[whereToSearch] = new Array();
  190.     var translatorsArryItem = translatorInfoItem[participant].translations[whereToSearch];
  191.     
  192.     translatorsArryItem.type = transData.lookupTransValue(participant, translation, "translationType").toLowerCase();
  193.  
  194.     translatorsArryItem.beginMegaLock = (transData.lookupTransValue(participant, translation, "beginMegaLock").toLowerCase() == "true");
  195.     translatorsArryItem.endMegaLock = (transData.lookupTransValue(participant, translation, "endMegaLock").toLowerCase() == "true");
  196.  
  197. /*
  198.     if (participant == "DataListOpenTags")
  199.     {
  200.         alert("PARSE...\n" +
  201.         participant + " " + whereToSearch + "\n" +
  202.         "Begin: " + translatorsArryItem.beginMegaLock + "\n" +
  203.         "End: " + translatorsArryItem.endMegaLock + "\n");
  204.     }
  205. */
  206.  
  207.     translatorsArryItem.lockAttributes = transData.lookupTransValue(participant, translation, "lockAttributes");
  208.  
  209.     translatorsArryItem.openTag = transData.lookupTransValue(participant, translation, "openTag");
  210.     
  211.     translatorsArryItem.display = transData.lookupTransValue(participant, translation, "display");
  212.     //For localization purposes: if display string is MM.LABEL_????, it's a global var (from Startup folder), so eval it.
  213.     if (translatorsArryItem.display && translatorsArryItem.display.indexOf("MM.LABEL_")==0)
  214.       translatorsArryItem.display = eval(translatorsArryItem.display);
  215.     
  216.     translatorsArryItem.closeTag = transData.lookupTransValue(participant, translation, "closeTag");
  217.     
  218.     // Set translatorsArryItem.attributes to a array of name/value pairs
  219.     // Set translatorsArryItem.data.attributes to a space-delimited list of values...?
  220.     var attributes = "";
  221.     var attributeArry = transData.lookupTransArray(participant, translation, "attributes");
  222.     if (attributeArry && attributeArry.length)
  223.     {
  224.       translatorsArryItem.attributes = new Array();
  225.       for (var k = 0; k < attributeArry.length; k++)
  226.       {
  227.         translatorsArryItem.attributes[attributeArry[k]] =
  228.           dw.getExtDataValue(participant, "translator", "translations", translation, "attributes", attributeArry[k]);  
  229.       }
  230.       var quickAttributes = new QuickString();
  231.       for (var attributeName in translatorsArryItem.attributes)
  232.       {
  233.         var attribute = translatorsArryItem.attributes[attributeName];
  234.         if (attribute && attribute.length)
  235.           {
  236.             quickAttributes.add(" ");
  237.             quickAttributes.add(attribute);
  238.           }
  239.       }
  240.       attributes = quickAttributes.toString();
  241.     }
  242.     
  243.     translatorsArryItem.insertBefore = transData.lookupTransValue(participant, translation, "insertBefore");
  244.     translatorsArryItem.insertAfter = transData.lookupTransValue(participant, translation, "insertAfter");
  245.     
  246.     translatorsArryItem.data = new transData(participant,
  247.                                              translatorsArryItem.type,
  248.                                              translatorsArryItem.openTag,
  249.                                              translatorsArryItem.closeTag,
  250.                                              attributes,
  251.                                              translatorsArryItem.display,
  252.                                              translatorsArryItem.insertBefore,
  253.                                              translatorsArryItem.insertAfter,
  254.                                              translatorsArryItem.beginMegaLock,
  255.                                              translatorsArryItem.endMegaLock,
  256.                                              translatorsArryItem.lockAttributes);
  257.   }
  258. }
  259.  
  260. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  261. // Function : transData_parse
  262. // Purpose    : pulls values out of XML <translation> tag and creates a new transData
  263. ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  264.  
  265. function transData_copy(data)
  266. {
  267.   return new transData(data.participant, data.type,
  268.                        data.openTag, data.closeTag,
  269.                        data.attributes, data.display,
  270.                        data.insertBefore, data.insertAfter,
  271.                        data.beginMegaLock, data.endMegaLock,
  272.                        data.lockAttributes);
  273. }
  274.